import { SwaggerObject, PathsObject, DefinitionsObject } from 'swagger-express-middleware'
import * as _ from 'lodash'

export interface ItemsObject {
    type: string
    format?: string
    items?: ItemsObject
    collectionFormat?: string
    'default'?: any
    maximum?: number
    exclusiveMaximum?: boolean
    minimum?: number
    exclusiveMinimum?: boolean
    maxLength?: number
    minLength?: number
    pattern?: string
    maxItems?: number
    minItems?: number
    uniqueItems?: boolean
    'enum'?: any[]
    multipleOf?: number
}

export interface ParameterObject {
    name: string
    'in': string
    description?: string
    required?: boolean
}

export interface GeneralParameterObject extends ParameterObject, ItemsObject {
    allowEmptyValue?: boolean
}

export interface ParametersDefinitionsObject {
    [index: string]: GeneralParameterObject
}

export interface PartialSwaggerObject {
    paths?: PathsObject
    definitions?: DefinitionsObject
    parameters?: ParametersDefinitionsObject
}

export { SwaggerObject }

export const merge = (swagger: SwaggerObject, partialSwaggers: PartialSwaggerObject[]): SwaggerObject => {
    return _.merge(swagger, ...partialSwaggers) as SwaggerObject
};
